import logging
import os
import datetime


def get_loggere(args):
    # 创建logger
    train_logger = logging.getLogger(f'{args.logger_name}_train')
    test_logger = logging.getLogger(f'{args.logger_name}_test')
    train_logger.setLevel(logging.INFO)
    test_logger.setLevel(logging.INFO)

    # 创建handler
    log_path = os.path.join(os.getcwd(), args.dataset)
    if not os.path.exists(log_path):
        os.mkdir(log_path)

    now = datetime.datetime.now().strftime('%Y-%m-%d')
    train_log_path = os.path.join(log_path, f'{now} train.log')
    test_log_path = os.path.join(log_path, f'{now} test.log')
    train_handler = logging.FileHandler(filename=train_log_path, mode='a')
    test_handler = logging.FileHandler(filename=test_log_path, mode='a')

    # 创建formatter
    formatter = logging.Formatter("[%(asctime)s | %(levelname)s%(message)s",
                                  datefmt='%H:%M:%S')

    train_handler.setFormatter(formatter)
    test_handler.setFormatter(formatter)
    train_logger.addHandler(train_handler)
    test_logger.addHandler(test_handler)

    return train_logger, test_logger
